﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');

FantastPlatform.UI.ResponsibilityAreaStreetForm = function (config) {
    Ext.apply(this, config);
    var newWidth = this.width;
    var newHeight = this.height;
    var thispoliceNum = this.policemanNumber;
    var grid1 = new FantastPlatform.UI.AreaStreetGrid({
        url: '../Service/ResponsibilityAreaStreet.aspx?Action=SearchStreetByResponsibilityAreaId&ResponsibilityAreaId=' + this.ResponsibilityAreaId,
        height: newHeight / 2,
        tbar: [
            {
                text: '移出负责街道中已有的街道',
                iconCls: 'delete',
                handler: removeStreet

            }, '-', {
                text: '刷新',
                iconCls: 'updata',
                handler:function(){ grid1.onUpdataGrid(); }
            }, '->',
            {
                tooltip: { text: '可以通过拖拽到下面的列表进行删除', title: '删除许可', autoHide: true },
                iconCls: 'down'
            }
            ]
    });
    grid1.onUpdataGrid();

    var grid2 = new FantastPlatform.UI.AreaStreetGrid({
        url: '../Service/ResponsibilityAreaStreet.aspx?Action=GetStreets',
        height: newHeight / 2,
        tbar: [
            {
                text: '给负责街道中添加新的街道',
                iconCls: 'add',
                handler: addStreet
            }, '->',
            {
                tooltip: { text: '可以通过拖拽到上面的列表进行添加', title: '添加许可', autoHide: true },
                iconCls: 'up'
            }
        ]
    })
    grid2.onUpdataGrid();

    var u_tpl = new Ext.Template(
    '<p>警员名称: {name}</p>',
    '<p>警员编码: {code}</p>',
       '<p>警员描述:{description}</p>'
);

    var uRoleInfo = new Ext.Panel({
        border: false,
        height: newHeight / 2,
        style: 'border:solid 1px',
        title: '警员信息',
        split: true,
        bodyStyle: 'padding:5px 5px 0',
        collapsible: true,
        autoLoad: { url: '../Setting/AStreetForm.aspx?Id=' + this.ResponsibilityAreaId, scripts: true }
    })

    var uSearchInfo = new Ext.form.FormPanel
    ({
        border: false,
        title: '查询条件',
        split: true,
        url: '../Service/ResponsibilityAreaStreet.aspx?Action=GetStreets',
        style: 'border:solid 1px',
        labelWidth: 50,
        bodyStyle: 'padding:5px 5px 0',
        height: newHeight / 2,
        defaultType: 'textfield',
        collapsible: true,
        defaults: { width: 120 },
        tbar: ['从负责街道未添加的街道表中查询'],
        items: [{
            fieldLabel: '关键字',
            name: 'Key'
        }],
        buttons: [{
            text: '提交查询',
            handler: function () { onStreetSearchClick(uSearchInfo, grid2, null); }
        }]
    });

    this.items = [{
        columnWidth: .7,
        width: 500,
        height: newHeight / 2,
        border: false,
        items: [grid1]
    }, {
        columnWidth: .3,
        width: 160,
        height: newHeight / 2,
        border: false,
        items: [uRoleInfo]
    }, {
        columnWidth: .7,
        width: 500,
        height: newHeight / 2,
        border: false,
        items: [grid2]
    }, {
        columnWidth: .3,
        width: 160,
        height: newHeight / 2,
        border: false,
        items: [uSearchInfo]
    }];

    var ResponsibilityAreaId = this.ResponsibilityAreaId;
    //alert(ResponsibilityAreaId);
    function removeStreet() {
        var node = checkGridSelected(grid1);
        if (node) {
            if (getIdFromGrid(node, 'Number') == thispoliceNum) {
                Ext.Msg.alert('提示', '不能将自己从该负责街道中移除');
            }
            else {
                Ext.Msg.confirm('提示', '确认要移除负责街道中已有的街道？', function (btn) {
                    if (btn == 'yes') {
                        Ext.Msg.wait('正在移除负责街道中已有街道……', '移除');
                        var fIds = getIdFromGrid(node, 'Id');
                        ajaxCalled(null, '../Service/ResponsibilityAreaStreet.aspx?Action=RemoveStreet&ResponsibilityAreaId=' + ResponsibilityAreaId, fIds, grid1, null);
                    }
                });
            }
        }
    }

    function addStreet() {
        var node = checkGridSelected(grid2);
        if (node) {
            Ext.Msg.confirm('提示', '确认要添加街道到该警员中？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在街道到警员中……', '添加');
                    var fIds = getIdFromGrid(node, 'Id');
                    //alert(fIds);
                    ajaxCalled(null, '../Service/ResponsibilityAreaStreet.aspx?Action=AddStreet&ResponsibilityAreaId=' + ResponsibilityAreaId, fIds, grid1, null);
                }
            })
        }
    }

    function onStreetSearchClick(form, grid, sender, fn) {
        if (form.form.isValid()) {
            var dataStr = form.form.getValues().Key;
            grid2.store.removeAll();
            grid2.store.proxy.conn = { method: 'post', url: '../Service/ResponsibilityAreaStreet.aspx?Action=GetStreets' };
            grid2.store.load({ params: { start: 0, limit: grid2.paperBar.getPageNumber(), dir: '', sort: '', code: dataStr} });
        }
    }
    FantastPlatform.UI.ResponsibilityAreaStreetForm.superclass.constructor.call(this, {
        layout: 'column',
        border: false
    });
};

Ext.extend(FantastPlatform.UI.ResponsibilityAreaStreetForm, Ext.Panel, {

});